package com.mcc.app.process.controller;

import com.fasterxml.jackson.annotation.JsonFormat;
import com.mcc.app.process.domain.Bellows;
import com.mcc.app.process.service.IBellowsService;
import com.mcc.common.annotation.Log;
import com.mcc.common.core.controller.BaseController;
import com.mcc.common.core.domain.AjaxResult;
import com.mcc.common.core.page.TableDataInfo;
import com.mcc.common.enums.BusinessType;
import com.mcc.common.utils.poi.ExcelUtil;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Date;
import java.util.List;

/**
 * 风箱Controller
 *
 * @author sg
 * @date 2021-09-03
 */
@RestController
@RequestMapping("/stock/bellows")
public class BellowsController extends BaseController
{
    @Autowired
    private IBellowsService bellowsService;

    /**
     * 查询风箱列表
     */
    @GetMapping("/list")
    public AjaxResult<TableDataInfo<Bellows>> list(Bellows bellows)
    {
        startPage();
        List<Bellows> list = bellowsService.selectBellowsList(bellows);
        return getDataTable(list);
    }

    /**
     * 导出风箱列表
     */
    @Log(title = "风箱", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(Bellows bellows)
    {
        List<Bellows> list = bellowsService.selectBellowsList(bellows);
        ExcelUtil<Bellows> util = new ExcelUtil<Bellows>(Bellows.class);
        return util.exportExcel(list, "bellows");
    }

    /**
     * 获取风箱详细信息
     */
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(bellowsService.selectBellowsById(id));
    }

    /**
     * 新增风箱
     */
    @Log(title = "风箱", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Bellows bellows)
    {
        return toAjax(bellowsService.insertBellows(bellows));
    }

    /**
     * 修改风箱
     */
    @Log(title = "风箱", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Bellows bellows)
    {
        return toAjax(bellowsService.updateBellows(bellows));
    }

    /**
     * 删除风箱
     */
    @Log(title = "风箱", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(bellowsService.deleteBellowsByIds(ids));
    }

    /**
     * 风箱图表
     * @param bellowId
     * @param startDt
     * @param endDt
     * @return
     */
    @GetMapping("/getBellowDataDialog")
    public AjaxResult getBellowDataDialog(String bellowId, String startDt, String endDt) {
        return AjaxResult.success(bellowsService.getBellowDataDialog(bellowId, startDt, endDt));
    }

    @ApiOperation("按日查询产能与速度考核")
    @GetMapping("/getBellowsDataNow")
    public AjaxResult getBellowsDataNow(String bellowId) {
        return AjaxResult.success(bellowsService.getBellowsDataNow(bellowId));
    }

}
